<?php
/**
 * @author 天涯 <mail@phpha.com>
 * @copyright http://blog.phpha.com
 * @link http://blog.phpha.com/vncms
 * @version 1.0
 */
defined('APP_PATH') or exit('Access Denied');
class m_gaacl extends spModel{
	public $table = 'gaacl';
	public $pk = 'group_id';
	//查询权限并缓存
	public function check(){
		//创始人组所有权限
		if($_SESSION['admin']['gid'] == 0 && $_SESSION['admin']['root'] == 1){
			return true;
		}
		//无需验证的权限
		$allowAcl = array('upld_img','upld_doup');
		//当前管理组权限
		$filename = APP_PATH.'/cache/group_'.$_SESSION['admin']['gid'].'.aacl';
		if(file_exists($filename)){
			$myAcl = unserialize(file_get_contents($filename));
		}else{
			$myAcl = array();
			$aclId = $this->findAll(array('group_id'=>$_SESSION['admin']['gid']));
			foreach($aclId as $v){
				$theAcl = spClass('m_aacl')->find(array('id'=>$v['aacl_id']));
				if(false != strpos($theAcl['action'], '|')){
					$action = explode('|', $theAcl['action']);
					foreach($action as $v){
						$myAcl[] = $theAcl['control'] . '_' . $v;						
					}
				}else{
					$myAcl[] = $theAcl['control'] . '_' . $theAcl['action'];
				}
			}
			file_put_contents($filename, serialize($myAcl));
		}
		global $__controller, $__action;
		return in_array($__controller.'_'.$__action, array_merge($myAcl,$allowAcl));
	}
}